package com.jie.jie.xiaohua.ui;

import android.content.Intent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ant.liao.GifView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.jaydenxiao.common.base.BaseActivity;
import com.jie.jie.R;

import java.net.HttpURLConnection;
import java.net.URL;

import butterknife.Bind;
import butterknife.OnClick;

public class QutuActivity extends BaseActivity {


    @Bind(R.id.back_iv)
    ImageView backIv;
    @Bind(R.id.title_tv)
    TextView titleTv;
    @Bind(R.id.qutu_iv)
    ImageView qutuIv;
    @Bind(R.id.qutu_gif)
    GifView qutuGif;
    @Bind(R.id.activity_qutu)
    LinearLayout activityQutu;

    @Override
    public int getLayoutId() {
        return R.layout.activity_qutu;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {
        Intent intent = getIntent();
        String title = intent.getStringExtra("title");
        String url = intent.getStringExtra("url");
        titleTv.setText(title);
        if (url.substring(url.lastIndexOf("."), url.length()).equals("gif")) {
            try {

                URL url1 = new URL(url);
                HttpURLConnection conn = (HttpURLConnection) url1.openConnection();
                conn.setConnectTimeout(5000);
                conn.setReadTimeout(5000);
                conn.connect();
                if (conn.getResponseCode() == 200) {
                    qutuGif.setGifImage(conn.getInputStream());
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
            }
        } else {
            Glide.with(this).load(url).diskCacheStrategy(DiskCacheStrategy.ALL).into(qutuIv);
        }
    }

    @OnClick(R.id.back_iv)
    public void onClick() {
        finish();
    }
}
